<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title>tango.io.digest.MerkleDamgard</title>
  <link href="./css/style.css" rel="stylesheet" type="text/css"/>
  <!-- <link href="./img/icon.png" rel="icon" type="image/png"/> -->
  <script type="text/javascript" src="./js/jquery.js"></script>
  <script type="text/javascript" src="./js/modules.js"></script>
  <script type="text/javascript" src="./js/quicksearch.js"></script>
  <script type="text/javascript" src="./js/navigation.js"></script>
  <!--<script type="text/javascript" src="./js/jquery.treeview.js"></script>-->
  <script type="text/javascript">
    var g_moduleFQN = "tango.io.digest.MerkleDamgard";
  </script>
  
</head>
<body>
<div id="content">
  <h1><a href="./htmlsrc/tango.io.digest.MerkleDamgard.html" class="symbol">tango.io.digest.MerkleDamgard</a></h1>
  
<p class="sec_header">License:</p>BSD style: see doc/license.txt for details
<p class="sec_header">Version:</p>Initial release: Feb 2006
<p class="sec_header">Author:</p>Regan Heath, Oskar Linde
<p class="bl"/>
        This module implements a generic Merkle-Damgard hash function
<dl>
<dt class="decl">class <a class="symbol _class" name="MerkleDamgard" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L59" kind="class" beg="59" end="397">MerkleDamgard</a> : Digest; <span class="attrs">[<span class="prot">package</span>]</span> <a title="Permalink to this symbol" href="#MerkleDamgard" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L59">#</a></dt>
<dd class="ddef">
<div class="summary">Extending MerkleDamgard to create a custom hash function requires 
        the implementation of a number of abstract methods. These include:
        <pre class="d_code">
<span class="k">public</span> <span class="k">uint</span> <span class="i">digestSize</span>();
<span class="k">protected</span> <span class="k">void</span> <span class="i">reset</span>();
<span class="k">protected</span> <span class="k">void</span> <span class="i">createDigest</span>(<span class="k">ubyte</span>[] <span class="i">buf</span>);
<span class="k">protected</span> <span class="k">uint</span> <span class="i">blockSize</span>();
<span class="k">protected</span> <span class="k">uint</span> <span class="i">addSize</span>();
<span class="k">protected</span> <span class="k">void</span> <span class="i">padMessage</span>(<span class="k">ubyte</span>[] <span class="i">data</span>);
<span class="k">protected</span> <span class="k">void</span> <span class="i">transform</span>(<span class="k">ubyte</span>[] <span class="i">data</span>);
</pre></div>
In addition there exist two further abstract methods; these methods
        have empty default implementations since in some cases they are not
<p class="sec_header">required:</p><pre class="d_code">
<span class="k">protected</span> <span class="k">abstract</span> <span class="k">void</span> <span class="i">padLength</span>(<span class="k">ubyte</span>[] <span class="i">data</span>, <span class="k">ulong</span> <span class="i">length</span>);
<span class="k">protected</span> <span class="k">abstract</span> <span class="k">void</span> <span class="i">extend</span>();
</pre>
<p class="bl"/>
        The method padLength() is required to implement the SHA series of
        Hash functions and also the Tiger algorithm. Method extend() is 
        required only to implement the MD2 digest.
<p class="bl"/>
        The basic sequence of internal events is as follows:
        <ul>
        <li>transform(), 0 or more times</li>
        <li>padMessage()</li>
        <li>padLength()</li>
        <li>transform()</li>
        <li>extend()</li>
        <li>createDigest()</li>
        <li>reset()</li>
        </ul>
<dl>
<dt class="decl">void <a class="symbol _function" name="MerkleDamgard.createDigest" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L76" kind="function" beg="76" end="76">createDigest</a><span class="params">(ubyte[] <em>buf</em>)</span>; <span class="attrs">[<span class="prot">protected</span>, <span class="stc">abstract</span>]</span> <a title="Permalink to this symbol" href="#MerkleDamgard.createDigest" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L76">#</a></dt>
<dd class="ddef">
<div class="summary">Constructs the digest</div>
<p class="sec_header">Params:</p>
<table class="params">
<tr><td><em>buf</em></td><td>a buffer with enough space to hold the digest</td></tr></table>
<p class="sec_header">Remarks:</p>Constructs the digest.</dd>
<dt class="decl">uint <a class="symbol _function" name="MerkleDamgard.blockSize" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L91" kind="function" beg="91" end="91">blockSize</a><span class="params">()</span>; <span class="attrs">[<span class="prot">protected</span>, <span class="stc">abstract</span>]</span> <a title="Permalink to this symbol" href="#MerkleDamgard.blockSize" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L91">#</a></dt>
<dd class="ddef">
<div class="summary">Digest block size</div>
<p class="sec_header">Returns:</p>the block size
<p class="sec_header">Remarks:</p>Specifies the size (in bytes) of the block of data to pass to
                each call to transform().</dd>
<dt class="decl">uint <a class="symbol _function" name="MerkleDamgard.addSize" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L108" kind="function" beg="108" end="108">addSize</a><span class="params">()</span>; <span class="attrs">[<span class="prot">protected</span>, <span class="stc">abstract</span>]</span> <a title="Permalink to this symbol" href="#MerkleDamgard.addSize" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L108">#</a></dt>
<dd class="ddef">
<div class="summary">Length padding size</div>
<p class="sec_header">Returns:</p>the length padding size
<p class="sec_header">Remarks:</p>Specifies the size (in bytes) of the padding which
                uses the length of the data which has been fed to the
                algorithm, this padding is carried out by the
                padLength method.</dd>
<dt class="decl">void <a class="symbol _function" name="MerkleDamgard.padMessage" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L125" kind="function" beg="125" end="125">padMessage</a><span class="params">(ubyte[] <em>data</em>)</span>; <span class="attrs">[<span class="prot">protected</span>, <span class="stc">abstract</span>]</span> <a title="Permalink to this symbol" href="#MerkleDamgard.padMessage" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L125">#</a></dt>
<dd class="ddef">
<div class="summary">Pads the digest data</div>
<p class="sec_header">Params:</p>
<table class="params">
<tr><td><em>data</em></td><td>a slice of the digest buffer to fill with padding</td></tr></table>
<p class="sec_header">Remarks:</p>Fills the passed buffer slice with the appropriate
                padding for the final call to transform(). This
                padding will fill the message data buffer up to
                blockSize()-addSize().</dd>
<dt class="decl">void <a class="symbol _function" name="MerkleDamgard.padLength" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L142" kind="function" beg="142" end="142">padLength</a><span class="params">(ubyte[] <em>data</em>, ulong <em>length</em>)</span>; <span class="attrs">[<span class="prot">protected</span>]</span> <a title="Permalink to this symbol" href="#MerkleDamgard.padLength" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L142">#</a></dt>
<dd class="ddef">
<div class="summary">Performs the length padding</div>
<p class="sec_header">Params:</p>
<table class="params">
<tr><td><em>data</em></td><td>the slice of the digest buffer to fill with padding</td></tr>
<tr><td><em>length</em></td><td>the length of the data which has been processed</td></tr></table>
<p class="sec_header">Remarks:</p>Fills the passed buffer slice with addSize() bytes of padding
                based on the length in bytes of the input data which has been
                processed.</dd>
<dt class="decl">void <a class="symbol _function" name="MerkleDamgard.transform" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L159" kind="function" beg="159" end="159">transform</a><span class="params">(ubyte[] <em>data</em>)</span>; <span class="attrs">[<span class="prot">protected</span>, <span class="stc">abstract</span>]</span> <a title="Permalink to this symbol" href="#MerkleDamgard.transform" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L159">#</a></dt>
<dd class="ddef">
<div class="summary">Performs the digest on a block of data</div>
<p class="sec_header">Params:</p>
<table class="params">
<tr><td><em>data</em></td><td>the block of data to digest</td></tr></table>
<p class="sec_header">Remarks:</p>The actual digest algorithm is carried out by this method on
                the passed block of data. This method is called for every
                blockSize() bytes of input data and once more with the remaining
                data padded to blockSize().</dd>
<dt class="decl">void <a class="symbol _function" name="MerkleDamgard.extend" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L173" kind="function" beg="173" end="173">extend</a><span class="params">()</span>; <span class="attrs">[<span class="prot">protected</span>]</span> <a title="Permalink to this symbol" href="#MerkleDamgard.extend" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L173">#</a></dt>
<dd class="ddef">
<div class="summary">Final processing of digest.</div>
<p class="sec_header">Remarks:</p>This method is called after the final transform just prior to
                the creation of the final digest. The MD2 algorithm requires
                an additional step at this stage. Future digests may or may not
                require this method.</dd>
<dt class="decl"><a class="symbol _ctor" name="MerkleDamgard.this" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L185" kind="ctor" beg="185" end="189">this</a><span class="params">()</span>; <a title="Permalink to this symbol" href="#MerkleDamgard.this" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L185">#</a></dt>
<dd class="ddef">
<div class="summary">Construct a digest</div>
<p class="sec_header">Remarks:</p>Constructs the internal buffer for use by the digest, the buffer
                size (in bytes) is defined by the abstract method blockSize().</dd>
<dt class="decl">void <a class="symbol _function" name="MerkleDamgard.reset" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L200" kind="function" beg="200" end="203">reset</a><span class="params">()</span>; <span class="attrs">[<span class="prot">protected</span>]</span> <a title="Permalink to this symbol" href="#MerkleDamgard.reset" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L200">#</a></dt>
<dd class="ddef">
<div class="summary">Initialize the digest</div>
<p class="sec_header">Remarks:</p>Returns the digest state to its initial value</dd>
<dt class="decl">void <a class="symbol _function" name="MerkleDamgard.update" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L217" kind="function" beg="217" end="237">update</a><span class="params">(void[] <em>input</em>)</span>; <a title="Permalink to this symbol" href="#MerkleDamgard.update" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L217">#</a></dt>
<dd class="ddef">
<div class="summary">Digest additional data</div>
<p class="sec_header">Params:</p>
<table class="params">
<tr><td><em>input</em></td><td>the data to digest</td></tr></table>
<p class="sec_header">Remarks:</p>Continues the digest operation on the additional data.</dd>
<dt class="decl">ubyte[] <a class="symbol _function" name="MerkleDamgard.binaryDigest" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L251" kind="function" beg="251" end="277">binaryDigest</a><span class="params">(ubyte[] <em>buf</em> = null)</span>; <a title="Permalink to this symbol" href="#MerkleDamgard.binaryDigest" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L251">#</a></dt>
<dd class="ddef">
<div class="summary">Complete the digest</div>
<p class="sec_header">Returns:</p>the completed digest
<p class="sec_header">Remarks:</p>Concludes the algorithm producing the final digest.</dd>
<dt class="decl">void <a class="symbol _function" name="MerkleDamgard.littleEndian32" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L292" kind="function" beg="292" end="299">littleEndian32</a><span class="params">(ubyte[] <em>input</em>, uint[] <em>output</em>)</span>; <span class="attrs">[<span class="prot">protected</span>, <span class="stc">final</span>]</span> <a title="Permalink to this symbol" href="#MerkleDamgard.littleEndian32" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L292">#</a></dt>
<dd class="ddef">
<div class="summary">Converts 8 bit to 32 bit Little Endian</div>
<p class="sec_header">Params:</p>
<table class="params">
<tr><td><em>input</em></td><td>the source array</td></tr>
<tr><td><em>output</em></td><td>the destination array</td></tr></table>
<p class="sec_header">Remarks:</p>Converts an array of ubyte[] into uint[] in Little Endian byte order.</dd>
<dt class="decl">void <a class="symbol _function" name="MerkleDamgard.bigEndian32" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L314" kind="function" beg="314" end="321">bigEndian32</a><span class="params">(ubyte[] <em>input</em>, uint[] <em>output</em>)</span>; <span class="attrs">[<span class="prot">protected</span>, <span class="stc">final</span>]</span> <a title="Permalink to this symbol" href="#MerkleDamgard.bigEndian32" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L314">#</a></dt>
<dd class="ddef">
<div class="summary">Converts 8 bit to 32 bit Big Endian</div>
<p class="sec_header">Params:</p>
<table class="params">
<tr><td><em>input</em></td><td>the source array</td></tr>
<tr><td><em>output</em></td><td>the destination array</td></tr></table>
<p class="sec_header">Remarks:</p>Converts an array of ubyte[] into uint[] in Big Endian byte order.</dd>
<dt class="decl">void <a class="symbol _function" name="MerkleDamgard.littleEndian64" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L336" kind="function" beg="336" end="343">littleEndian64</a><span class="params">(ubyte[] <em>input</em>, ulong[] <em>output</em>)</span>; <span class="attrs">[<span class="prot">protected</span>, <span class="stc">final</span>]</span> <a title="Permalink to this symbol" href="#MerkleDamgard.littleEndian64" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L336">#</a></dt>
<dd class="ddef">
<div class="summary">Converts 8 bit to 64 bit Little Endian</div>
<p class="sec_header">Params:</p>
<table class="params">
<tr><td><em>input</em></td><td>the source array</td></tr>
<tr><td><em>output</em></td><td>the destination array</td></tr></table>
<p class="sec_header">Remarks:</p>Converts an array of ubyte[] into ulong[] in Little Endian byte order.</dd>
<dt class="decl">void <a class="symbol _function" name="MerkleDamgard.bigEndian64" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L357" kind="function" beg="357" end="364">bigEndian64</a><span class="params">(ubyte[] <em>input</em>, ulong[] <em>output</em>)</span>; <span class="attrs">[<span class="prot">protected</span>, <span class="stc">final</span>]</span> <a title="Permalink to this symbol" href="#MerkleDamgard.bigEndian64" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L357">#</a></dt>
<dd class="ddef">
<div class="summary">Converts 8 bit to 64 bit Big Endian</div>
<p class="sec_header">Params:</p>
<table class="params">
<tr><td><em>input</em></td><td>the source array</td></tr>
<tr><td><em>output</em></td><td>the destination array</td></tr></table>
<p class="sec_header">Remarks:</p>Converts an array of ubyte[] into ulong[] in Big Endian byte order.</dd>
<dt class="decl">uint <a class="symbol _function" name="MerkleDamgard.rotateLeft" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L379" kind="function" beg="379" end="396">rotateLeft</a><span class="params">(uint <em>x</em>, uint <em>n</em>)</span>; <span class="attrs">[<span class="prot">protected</span>, <span class="stc">final</span>]</span> <a title="Permalink to this symbol" href="#MerkleDamgard.rotateLeft" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.digest.MerkleDamgard.html#L379">#</a></dt>
<dd class="ddef">
<div class="summary">Rotate left by n</div>
<p class="sec_header">Params:</p>
<table class="params">
<tr><td><em>x</em></td><td>the value to rotate</td></tr>
<tr><td><em>n</em></td><td>the amount to rotate by</td></tr></table>
<p class="sec_header">Remarks:</p>Rotates a 32 bit value by the specified amount.</dd></dl></dd></dl>
</div>
<div id="footer">
  <p>Copyright (c) 2006 Tango. All rights reserved</p>
  <p>Page generated by <a href="http://code.google.com/p/dil">dil</a> on Fri Dec 26 04:04:02 2008. Rendered by <a href="http://code.google.com/p/dil/wiki/Kandil">kandil</a>.</p>
</div>
</body>
</html>